package com.quasar.hpatient.module.home_health;

import android.support.v7.widget.RecyclerView;

import com.quasar.hpatient.R;
import com.quasar.hpatient.dialog.ChooseSingleDialog;
import com.quasar.hpatient.dialog.ChooseTimeDialog;
import com.quasar.hpatient.dialog.DateDialog;
import com.quasar.hpatient.dialog.HealthDialog;

import java.util.Arrays;

import lib.quasar.base.frame.BaseActivity;
import lib.quasar.context.BaseApp;
import lib.quasar.context.BaseConstant;
import lib.quasar.widget.menu.NavigationView;

/**
 * description: 首页 ==> 健康史
 * created by kalu on 2018/3/29 9:03
 */
public class HealthActivity extends BaseActivity<HealthPresenter> implements HealthView {

    @Override
    public int initView() {
        return R.layout.activity_home_health;
    }

    @Override
    public void initDataLocal() {

        final NavigationView menu = findViewById(R.id.activity_home_health_menu);
        menu.setOnNavigationChangeListener((isBack, isMenu) -> {
            if (isBack) onBackPressed();
            else showAdd();
        });


        final RecyclerView recycler = findViewById(R.id.activity_home_health_list);
        getPresenter().initList(this, recycler);
    }

    @Override
    public void initDataNet() {

        final RecyclerView recycler = findViewById(R.id.activity_home_health_list);

        getPresenter().healthList(this, recycler, BaseConstant.NULL_STR, BaseConstant.NULL_STR, "all");
    }

    @Override
    public void showSingle(int position) {
        toast("长按");
    }

    @Override
    public void showInput() {

        final ChooseTimeDialog dialog = new ChooseTimeDialog(this);
        dialog.setOnDialogChangeListener(new ChooseTimeDialog.OnDialogChangeListener() {
            @Override
            public void onChange(String begin, String end) {

                final RecyclerView recycler = findViewById(R.id.activity_home_health_list);
                final String message = getResources().getString(R.string.home_health_time, begin, end);
                getPresenter().setTime(HealthActivity.this, recycler, message);
            }

            @Override
            public void onTop() {
                final DateDialog dialog1 = new DateDialog(HealthActivity.this);
                dialog1.setOnDateChangeListener((year, month, day) -> {
                    final String date = BaseApp.getResource().getString(R.string.home_health_date, year, month, day);
                    dialog.setTop(date);
                });
                dialog1.show();
            }

            @Override
            public void onBottom() {
                final DateDialog dialog1 = new DateDialog(HealthActivity.this);
                dialog1.setOnDateChangeListener((year, month, day) -> {
                    final String date = BaseApp.getResource().getString(R.string.home_health_date, year, month, day);
                    dialog.setBottom(date);
                });
                dialog1.show();
            }
        });
        dialog.show();
        dialog.setTitle("选择时间");
        dialog.setMenuName("开始时间：", "结束时间：");
    }

    @Override
    public void showTime() {

        final ChooseSingleDialog dialog = new ChooseSingleDialog(this);
        dialog.setOnDialogChangeListener(message -> {
            if ("自定义".equals(message)) showInput();
            else {
                final RecyclerView recycler = findViewById(R.id.activity_home_health_list);
                getPresenter().setTime(HealthActivity.this, recycler, message);
            }
        });
        dialog.show();
        dialog.setList(Arrays.asList("全部", "一周", "两周", "一月", "三月", "半年", "自定义"));
    }

    @Override
    public void showType() {

        final ChooseSingleDialog dialog = new ChooseSingleDialog(this);
        dialog.setOnDialogChangeListener(message -> {
            final RecyclerView recycler = findViewById(R.id.activity_home_health_list);
            getPresenter().setType(HealthActivity.this, recycler, message);
        });
        dialog.show();
        dialog.setList(Arrays.asList("全部", "病历信息", "诊断信息", "调药记录", "患者事件", "特殊事件", "重点"));
    }

    @Override
    public void showAdd() {
        final HealthDialog dialog = new HealthDialog(this);
        dialog.setOnDialogChangeListener((time, input) -> {
            final RecyclerView recycler = findViewById(R.id.activity_home_health_list);
            getPresenter().addMolde(HealthActivity.this, recycler, time, input);
        });
        dialog.show();
    }
}